import { reactive } from 'vue'
import { defineStore } from 'pinia'

// 定义userInfo 的约束接口
interface UserInfo {
  username: string
  nickname: string
}

export const useUserStore = defineStore('user', () => {
  // 定义userInfo 包括 username、password、nickname 默认为空
  const userInfo = reactive<UserInfo>({
    username: '',
    nickname: ''
  })

  // 设置用户信息
  const setUserInfo = ({ username, nickname }) => {
    userInfo.username = username
    userInfo.nickname = nickname
  }
  // 清空用户信息
  const clearUserInfo = () => {
    userInfo.username = ''
    userInfo.nickname = ''
  }

  return {
    userInfo,
    setUserInfo,
    clearUserInfo
  }
})
